package com.mathdroid.gui.splashscreen;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

import com.mathdroid.core.Config;
import com.mathdroid.exceptionhandling.ExceptionHandler;

/**
 * This JPanel loads the SplashScreen image from the class path and sets its
 * preferred size. A simple version text is shown, too.
 */
public final class SplashScreenPanel extends JPanel {
	/**
	 * Default UID.
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The class path to the image.
	 */
	private static final String PATH = 
		"/com/mathdroid/gui/images/splashscreen.png";
	
	/**
	 * The width of the image.
	 */
	private static final int WIDTH = 398;
	
	/**
	 * The height of the image.
	 */
	private static final int HEIGHT = 200;
	
	/**
	 * Standard constructor.
	 */
	public SplashScreenPanel() {
		super();
		this.setPreferredSize(new Dimension(WIDTH, HEIGHT));
	}
	
	@Override
	public void paintComponent(final Graphics g) {
		super.paintComponent(g);
		
		Image img = null;
		try {
			img = ImageIO.read(getClass().getResource(PATH));
			g.drawImage(img, 0, 0, WIDTH, HEIGHT, Color.BLACK, this);
		} catch (Exception e) {
			ExceptionHandler.report(
					"Could not find the splashscreen image.", e);
		}	
		final int spacing = 10;
		g.drawString(Config.getProperty("version"), spacing, HEIGHT - spacing);
	}
}
